<?php

/**
 * pages actions.
 *
 * @package    shop
 * @subpackage pages
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class pagesActions extends sfActionsEx
{
    public function executeIndex(){
      $this->news = NewsTable::getInstance()->createQuery()->select()->orderBy('create_time')->limit(4)->execute();
    }
    
    public function executeProduct(sfRequest $request){
        $id = $request->getParameter('id');
        if($id != NULL){
            $this->product = ProductTable::getInstance()->findOneBy('id', $id);
            if($this->product && !$this->product->getLocked()){
                $this->photos = $this->product->getProductImage();
            }
        }
    }
    
    public function executeProducts(sfRequest $request){
        $this->type = 'Undef';
        
        switch($request->getParameter('type')){
            case 'buty':
                $this->type = 'Buty';
                $id = 1;
                break;
            case 'odziez':
                $this->type = 'Odzież';
                $id = 2;
                break;
            case 'bielizna':
                $this->type = 'Bielizna';
                $id = 3;
                break;                
        }
        $arr = array();
        $prd = Doctrine_Query::create()->select()->from('ProductCattegoryRelation')->where('product_cattegory =? ', $id)->execute();  
        foreach($prd as $product){
            $obj = ProductTable::getInstance()->findOneBy('id', $product->getProductId());
            if($obj){
                $arr[] = $obj;
            }
        }
        $this->products = $arr;
    } 
   
    public function executeSearch(sfRequest $request){
        
    }
    
    public function executeAccountAdminister(sfRequest $request){
        if(!Authorization::getInstance()->isExists()){
            $this->redirect('@index');
        }
        $this->user = Authorization::getInstance()->getUser();
        $this->deliveryData = DeliveryDataTable::getInstance()->findOneBy('user_id', $this->user->getId());
        $this->newsletter = NewsletterTable::getInstance()->findOneBy('email', $this->user->getEmail());
    }
    
    public function executeRegisterAccount(sfRequest $request) {
        if(Authorization::getInstance()->isExists()){
            $this->redirect('@accountAdminister');
        }
    }
    
    public function executeLogin(sfRequest $request){
        if(Authorization::getInstance()->isExists()){
            $this->redirect('@accountAdminister');
        }
    }
     public function executeBucket(sfRequest $request){
        $this->bucket = myBucket::getInstance();
        $this->deliveryType = DeliveryTypeTable::getInstance()->findAll();
    }
}   
